﻿use actix_web::{http::header::ContentType, HttpResponse};
use actix_web_flash_messages::IncomingFlashMessages;
use std::fmt::Write;

pub async fn login_form(flash_message: IncomingFlashMessages) -> HttpResponse {
    let mut error_html = String::new();
    // 展示所有的消息层级，而不仅仅是错误
    for m in flash_message.iter() {
        writeln!(error_html, "<p><i>{}</i></p>", m.content()).unwrap()
    }
    HttpResponse::Ok()
        .content_type(ContentType::html())
        .body(format!(
            r#"
<!DOCTYPE html>
<html lang="en">

<head>
	{error_html}
	<meta http-equiv="content-type" content="text/html; charset=utf-8">
	<title>Login</title>
</head>

<body>
	<form action="/login" method="post">
		<label>Username
			<input type="text" placeholder="Enter Username" name="username">
		</label>

		<label>Password
			<input type="password" placeholder="Enter Password" name="password">
		</label>

		<button type="submit">Login</button>
	</form>
</body>

</html>
		"#
        ))
}
